/*****************************************************************************
 *   Copyright 2005 Tim A Wang
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 ****************************************************************************/
package com.jb.web.bean.event;

import com.jb.web.bean.Form;
import com.jb.web.context.WebContext;


/**
 * system command handles login, it uses sql authenticator to authentic your
 * user if logged in, then set the respondpage personalized flag to be false
 * so that will get personalized when renderred
 */
public class LoginEH {
    public void onLogin(WebContext pCtx, UIEvent event) {
        boolean logedin = pCtx.getSession().performAuthenticate(pCtx, event.getParameter("username"),
                event.getParameter("password"));
        Form form =(Form) event.getSource();
        String pageName = pCtx.getSession().getDeniedPage();
        
        if(pageName!=null)
            form.setActionForwards(pageName+".xsp");
        if (!logedin) {
            //leave the message to the security manager
            pCtx.renderResponse();
        }
    }
}
